import {SysCompanyInfoAdd, SysCompanyInfoData, SysCompanyInfoDetail, SysCompanyInfoParams} from "@/pages/company/type";
import {request} from "@@/plugin-request/request";
import download from "@/utils/download";
import {HttpResult, Page} from "@/services/typings";


export const sysCompanyInfoPageList = async (sysCompanyInfoParams: SysCompanyInfoParams) => {
    return request<HttpResult<Page<SysCompanyInfoData>>>('/api/company/list', {
        method: 'POST',
        data: sysCompanyInfoParams
    });
}


export const sysCompanyInfoUpdate = async (sysCompanyInfoAdd: SysCompanyInfoAdd) => {
    return request<HttpResult<string>>('/api/company/update', {
        method: 'POST',
        data: sysCompanyInfoAdd
    });
}

export const sysCompanyInfoAdd = async (sysCompanyInfoAdd: SysCompanyInfoAdd) => {
    return request<HttpResult<string>>('/api/company/add', {
        method: 'POST',
        data: sysCompanyInfoAdd
    });
}

export const sysCompanyInfoRemove = async ( ids: (number | string)[] ) => {
    return request<HttpResult<string>>('/api/company/remove', {
        method: 'POST',
        data: {
            ids
        }
    });
}

export const sysCompanyInfoDetail = async (id: number) => {
    return request<HttpResult<SysCompanyInfoDetail>>('/api/company/detail', {
        method: 'POST',
        data: {
            id
        }
    });
}

export const sysCompanyInfoImport = async (formData: FormData) => {
    return request<HttpResult<string>>('/Tag//import', {
        method: 'POST',
        data: formData,
        requestType: "form"
    });
}


const sysCompanyInfoExport = async (ids: (number | string)[]) => {
    return request<HttpResult<string>>('/Tag//export', {
        method: 'POST',
        data: {ids},
        responseType: 'blob',
        getResponse: true,
    });
}

export const downloadSysCompanyInfoExport = async (ids: (number | string)[]) => {
    await sysCompanyInfoExport(ids).then(({data, response}) => {
        download(data, response)
    });
}


const sysCompanyInfoExportTemplate = async () => {
    return request<HttpResult<string>>('/Tag//export/template', {
        method: 'POST',
        responseType: 'blob',
        getResponse: true,
    });
}

export const downloadSysCompanyInfoExportTemplate = async () => {
    await sysCompanyInfoExportTemplate().then(({data, response}) => {
        download(data, response)
    });
}




